package utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * @program: sporadic
 * @description:
 * @author: LHD   QQ:1727865856
 * @create: 2019-10-24 11:55
 **/
public class OrderId {
    public static String createOrderId() {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmSS");
        int hashCode = UUID.randomUUID().toString().hashCode();
        String formatDate = simpleDateFormat.format(date);
        String orderId = formatDate + "" + hashCode;
        System.out.println(orderId.indexOf("-"));
        if (orderId.indexOf("-") != -1) {
            int index = orderId.indexOf("-") - 1;
            int end = orderId.indexOf("-") + 1;
            orderId = orderId.substring(0, index) + orderId.substring(end);
        }
        return orderId.substring(0, 23);
    }

}
